<pre>
<tt>
<font color="#000080">#ifndef</font> __EXAMPLE__
<font color="#000080">#define</font> __EXAMPLE__


<font color="#000080">#include</font> <font color="#000000">"coid/coidsvc/coidsvc.h"</font>


<font color="#FF0000">//{client</font>
<font color="#FF0000">///Example struct used for argument in methods</font>
<font color="#0000FF">struct</font> FOO_STRUCT
<font color="#000080">{</font>
    <font color="#0000FF">charstr</font> message;
    <font color="#0000FF">int</font> * array;
    <font color="#0000FF">int</font> size;

    <font color="#000000">FOO_STRUCT(</font>) : <font color="#000000">array(</font>NULL), <font color="#000000">size(</font><font color="#00D000">0</font>) <font color="#000080">{</font><font color="#000080">}</font>

    FOO_STRUCT &amp; <font color="#0000FF">operator</font> = ( <font color="#0000FF">const</font> FOO_STRUCT &amp; x ) <font color="#000080">{</font>
        message = x.message; size = x.size;
        <font color="#0000FF">if</font>( array ) <font color="#000080">{</font><font color="#0000FF">delete</font> array; array = NULL;<font color="#000080">}</font>
        <font color="#0000FF">if</font>( size ) <font color="#000080">{</font>
            array = <font color="#0000FF">new</font> <font color="#0000FF">int</font>[size];
            <font color="#000000">memcpy(</font> array, x.array, size * <font color="#0000FF">sizeof</font>(<font color="#0000FF">int</font> *) );
        <font color="#000080">}</font>
        <font color="#0000FF">return</font> *<font color="#0000FF">this</font>;
    <font color="#000080">}</font>
    
    <font color="#FF0000">///write object to stream</font>
    <font color="#0000FF">friend</font> binstream &amp; <font color="#0000FF">operator</font> &lt;&lt; ( binstream &amp; b, <font color="#0000FF">const</font> FOO_STRUCT &amp; x ) <font color="#000080">{</font>
        b &lt;&lt; x.message &lt;&lt; x.size;
        <font color="#0000FF">if</font>( x.size ) b.<font color="#000000">write_raw(</font> x.array, x.size * <font color="#0000FF">sizeof</font>(<font color="#0000FF">int</font> *) );
        <font color="#0000FF">return</font> b;
    <font color="#000080">}</font>
    
    <font color="#FF0000">///read object from stream</font>
    <font color="#0000FF">friend</font> binstream &amp; <font color="#0000FF">operator</font> &gt;&gt; ( binstream &amp; b, FOO_STRUCT &amp; x ) <font color="#000080">{</font>
        b &gt;&gt; x.message &gt;&gt; x.size;
        <font color="#0000FF">if</font>( x.array ) <font color="#000080">{</font><font color="#0000FF">delete</font> x.array; x.array = NULL;<font color="#000080">}</font>
        <font color="#0000FF">if</font>( x.size ) <font color="#000080">{</font>
            x.array = <font color="#0000FF">new</font> <font color="#0000FF">int</font>[x.size];
            b.<font color="#000000">read_raw(</font> x.array, x.size * <font color="#0000FF">sizeof</font>(<font color="#0000FF">int</font> *) );
        <font color="#000080">}</font>
        <font color="#0000FF">return</font> b;
    <font color="#000080">}</font>
<font color="#000080">}</font>;
<font color="#FF0000">//}client</font>



<font color="#FF0000">///Structure for remapping example, server side</font>
<font color="#0000FF">struct</font> REMAP_EXAMPLE
<font color="#000080">{</font>
    <font color="#0000FF">const</font> <font color="#0000FF">char</font> * err_text;
    <font color="#000000">REMAP_EXAMPLE(</font>) : <font color="#000000">err_text(</font>NULL) <font color="#000080">{</font><font color="#000080">}</font>
    <font color="#0000FF">friend</font> binstream &amp; <font color="#0000FF">operator</font> &lt;&lt; ( binstream &amp; b, <font color="#0000FF">const</font> REMAP_EXAMPLE &amp; x ) <font color="#000080">{</font>
        <font color="#0000FF">return</font> b &lt;&lt; x.err_text;
    <font color="#000080">}</font>
<font color="#000080">}</font>;


<font color="#FF0000">/*{client_only</font>
<font color="#FF0000">///Structure for remapping example, client side</font>
<font color="#FF0000">struct REMAP_EXAMPLE_clientside</font>
<font color="#FF0000">{</font>
<font color="#FF0000">    charstr err_text;</font>
<font color="#FF0000">    friend binstream &amp; operator &gt;&gt; ( binstream &amp; b, REMAP_EXAMPLE_clientside &amp; x ) {</font>
<font color="#FF0000">        x.err_text.reset();</font>
<font color="#FF0000">        int tmp;</font>
<font color="#FF0000">        b &gt;&gt; tmp;</font>
<font color="#FF0000">        if( tmp ) {</font>
<font color="#FF0000">            char * str = x.err_text.get_append_buf( tmp+1 );</font>
<font color="#FF0000">            b.read_raw( str, tmp );</font>
<font color="#FF0000">            str[tmp] = 0;</font>
<font color="#FF0000">        }</font>
<font color="#FF0000">        return b;</font>
<font color="#FF0000">    }</font>
<font color="#FF0000">};</font>
<font color="#FF0000">}client_only</font>
<font color="#FF0000">*/</font>




<font color="#FF0000">///Example decorated class</font>
<font color="#0000FF">class</font> example
<font color="#000080">{</font>
    cmd_interface * _cmdin;
    FOO_STRUCT      _fs;

<font color="#0000FF">public</font>:
    <font color="#000000">example(</font>) : <font color="#000000">_cmdin(</font>NULL)  <font color="#000080">{</font><font color="#000080">}</font>


    <font color="#FF0000">//some optional special functions, recognized by coidgen tool</font>
    <font color="#8800A3">net_fnc_s</font> <font color="#0000FF">opcd</font> <font color="#000000">accept_startup_params(</font> cmd_interface &amp; cmd ) <font color="#000080">{</font>_cmdin = &amp;cmd; <font color="#0000FF">return</font> <font color="#00D000">0</font>;<font color="#000080">}</font>
    <font color="#8800A3">net_fnc_s</font> <font color="#0000FF">opcd</font> <font color="#000000">accept_connect(</font> <font color="#0000FF">const</font> <font color="#0000FF">charstr</font> &amp; name, <font color="#8800A3">net_nolog</font> <font color="#0000FF">const</font> password &amp; pwd ) <font color="#000080">{</font><font color="#0000FF">return</font> <font color="#00D000">0</font>;<font color="#000080">}</font>


    <font color="#FF0000">//user functions</font>
    <font color="#8800A3">net_fnc</font> <font color="#8800A3">net_nolog</font> <font color="#0000FF">opcd</font> <font color="#000000">read1(</font> <font color="#8800A3">net_out</font>   FOO_STRUCT  &amp; list )    <font color="#000080">{</font>list =  _fs; <font color="#0000FF">return</font> <font color="#00D000">0</font>;<font color="#000080">}</font>
    <font color="#8800A3">net_fnc</font> <font color="#8800A3">net_nolog</font> <font color="#0000FF">opcd</font> <font color="#000000">read2(</font> <font color="#8800A3">net_fetch</font> FOO_STRUCT *&amp; list )    <font color="#000080">{</font>list = &amp;_fs; <font color="#0000FF">return</font> <font color="#00D000">0</font>;<font color="#000080">}</font>

    <font color="#8800A3">net_fnc</font> <font color="#8800A3">net_nolog</font> <font color="#0000FF">opcd</font> <font color="#000000">send(</font> <font color="#8800A3">net_inout</font> <font color="#0000FF">int</font> &amp; ref, <font color="#0000FF">const</font> <font color="#0000FF">charstr</font> &amp; command, <font color="#8800A3">net_out</font> binstreambuf &amp; reply ) <font color="#0000FF">const</font>
    <font color="#000080">{</font>
        <font color="#0000FF">return</font> <font color="#00D000">0</font>;
    <font color="#000080">}</font>

    <font color="#8800A3">net_fnc</font> <font color="#0000FF">opcd</font> <font color="#000000">remap_fnc(</font> <font color="#8800A3">net_out</font> <font color="#8800A3">net_remap</font>(REMAP_EXAMPLE_clientside &amp;) REMAP_EXAMPLE &amp; arg ) <font color="#000080">{</font>
        arg.err_text = <font color="#000000">"Foo"</font>;
        <font color="#0000FF">return</font> <font color="#00D000">0</font>;
    <font color="#000080">}</font>

    <font color="#FF0000">//method available only in direct (client&amp;server in the same process) mode</font>
    <font color="#8800A3">net_fnc_d</font> <font color="#0000FF">opcd</font> <font color="#000000">get_ptr(</font> FOO_STRUCT ** f )   <font color="#000080">{</font>*f = &amp;_fs; <font color="#0000FF">return</font> <font color="#00D000">0</font>;<font color="#000080">}</font>
<font color="#000080">}</font>;


<font color="#000080">#endif</font> <font color="#FF0000">// !__EXAMPLE__</font>
</tt>
</pre>
